# 字符串是不可变的
#1.字符串格式化
#2.字符串方法
formatEx = "Hello,%s. %s enough for ya?"
values = ('world','Hot')
print(formatEx % values)


stringA = "Hello World!"
print(stringA[0])
print("www","runoob","com",sep=".")


# print('%10f' % PI)

#字符串格式化示例
width = 35 # input('Please enter width:')
price_width = 10
item_width = width - price_width
header_format = '%-*s%*s'
formatE = '%-*s%*.2f'

print('='*width)
print(header_format % (item_width,'Item',price_width,'Price'))
print('-'*width)
print(formatE % (item_width,'Apples',price_width,0.4))
print(formatE % (item_width,'Pears',price_width,0.5))
print(formatE % (item_width,'Cantaloupes',price_width,1.92))
print(formatE % (item_width,'Dried APricots(16 oz.)',price_width,8))
print('='*width)


# 1.find():查找字符串
print("Monty Python's Flying Circus".find("Monty"))
print("Monty Python's Flying Circus".find("AAA"))  # -1

subject = '$$$ Get rich now !!! $$$'
print(subject.find('$$$')) # 0
print(subject.find('$$$',1)) # 21
print(subject.find('!!!')) # 17
#可以接受可选的起始点和结束点参数，注意不包含第二个索引
print(subject.find('!!!',0,16))# -1


#2.join():添加的队列元素都必须是字符串
seq = [1,2,3,4,5]
sep = '+'
# print(sep.join(seq)) #会报错

seq2 = ['1','2','3','4','5']
joinResult = sep.join(seq2)
print(joinResult) 

#3. lower()/islower()/capitalize/title/upper/isupper
print("Gram".lower())

#4.replace():替换匹配项
stringB = "This is a test"
print(stringB.replace('is','eez'))

#5.split():分割
print(joinResult.split('+'))
#不提供任何分隔符，默认把所有空格作为分隔符（空格、制表、换行等）
print('Using the default '.split())

#6.strip():去除两侧（不包括内部）空格
print('    Using the default '.strip())
print('****   Using ** the default !!! ***'.strip('*!'))

#7.translate():可以替换字符串中的某些部分，translate只处理单个字符
